//
//  DYNavigationController.m
//  Excellence
//
//  Created by 帝云科技 on 2017/6/16.
//  Copyright © 2017年 diyunkeji. All rights reserved.
//

#import "DYNavigationController.h"

@interface DYNavigationController ()<
UINavigationControllerDelegate>

@property (nonatomic, strong) CATransition *transition;

@end

@implementation DYNavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;
    [self initNavigation];
}

- (void)initNavigation
{
    UINavigationBar *navBar = [UINavigationBar appearance];
    [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor xhq_aTitle],
                                     NSFontAttributeName: [UIFont systemFontOfSize:17]}];
    [navBar setBarTintColor:[UIColor whiteColor]];
    navBar.opaque = NO;
    navBar.translucent = NO;
    [[UIBarButtonItem appearance] setTintColor:[UIColor xhq_content]];
    
    //去掉黑线
    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    
    //设置状态栏字体颜色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

#pragma mark - UINavigationControllerDelegate
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0)
    {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    if (self.viewControllers.count > 0 && !viewController.navigationItem.leftBarButtonItem)
    {
        viewController.navigationItem.leftBarButtonItem = [self backButtonItem];
    }
    [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    self.transition = (CATransition *)[navigationController.view.layer animationForKey:kCATransition];
}

#pragma mark - 返回按钮
- (UIBarButtonItem *)backButtonItem
{
    return [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_back"]
                                            style:UIBarButtonItemStylePlain
                                           target:self
                                           action:@selector(back)];
}

- (void)back
{
     [self popViewControllerAnimated:YES];
//    if (self.transition)
//    {
//
//    }
//    else
//    {
//        [self popViewControllerAnimated:YES];
//    }
}

@end
